package com.jcl.recruit.console.user.mapper;

import com.jcl.recruit.console.user.model.SysUser;

import static org.apache.ibatis.jdbc.SqlBuilder.*;


public class SysUserSqlProvider {

    String TABLE_NAME = "t_sys_user";

    public String insert(SysUser entity) {
        BEGIN();
        INSERT_INTO(TABLE_NAME);
        
        if (entity.getRealName() != null) {
            VALUES("real_name", "#{realName,jdbcType=VARCHAR}");
        }
        if (entity.getUsername() != null) {
            VALUES("username", "#{username,jdbcType=VARCHAR}");
        }
        if (entity.getPassword() != null) {
            VALUES("password", "#{password,jdbcType=VARCHAR}");
        }
        if (entity.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }
        if (entity.getUpdateTime() != null) {
            VALUES("update_time", "#{updateTime,jdbcType=TIMESTAMP}");
        }
        if (entity.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }

    public String updateByPrimaryKey(SysUser entity) {
        BEGIN();
        UPDATE(TABLE_NAME);
        
        if (entity.getRealName() != null) {
            SET("real_name = #{realName,jdbcType=VARCHAR}");
        }
        if (entity.getUsername() != null) {
            SET("username = #{username,jdbcType=VARCHAR}");
        }
        if (entity.getPassword() != null) {
            SET("password = #{password,jdbcType=VARCHAR}");
        }
        if (entity.getStatus() != null) {
            SET("status = #{status,jdbcType=INTEGER}");
        }
        if (entity.getUpdateTime() != null) {
            SET("update_time = #{updateTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}